﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using FontStashSharp;
using MonoGame.Extended;

namespace FNALearn
{
    internal partial class FNAGame : Game
    {
        private SpriteBatch _spriteBatch;
        private FontStashSharp.FontSystem _fontSystem;

        static void Main(string[] args)
        {
            using (var g = new FNAGame())
            {
                g.Run();
            }
        }

        public FNAGame()
        {
            InitGraphicsDeviceManager();
        }

        private void InitGraphicsDeviceManager()
        {
            var gdm = new GraphicsDeviceManager(this);
            gdm.IsFullScreen = false;
            this.IsMouseVisible = true;
        }

        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            LoadFont();

            base.LoadContent();
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            _spriteBatch.Begin();

            var font = _fontSystem.GetFont(144);
            var text = "你好，世界！";
            var size = font.MeasureString(text);
            _spriteBatch.DrawString(font, text, -Vector2.UnitX * size.X / 2, Color.White, effect: FontSystemEffect.Stroked);

            _spriteBatch.DrawCircle(new CircleF() { Center = Vector2.Zero, Radius = 100 }, 32, Color.Red, 1);
            
            _spriteBatch.End();

            base.Draw(gameTime);
        }


        private void LoadFont()
        {
            var fontFilePath = @"E:\Projects\FNALearn\FNALearn\Fonts\SourceHanSansSC-Heavy.otf";
            _fontSystem = new FontSystem();

            _fontSystem.AddFont(File.ReadAllBytes(fontFilePath));
        }
    }
}
